//
//  CPRegisterVC.m
//  CPApp
//
//  Created by yobet on 2018/3/23.
//  Copyright © 2018年 Class. All rights reserved.
//

#import "CPRegisterVC.h"
#import "CPTabbarController.h"
@interface CPRegisterVC ()
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (weak, nonatomic) IBOutlet UITextField *email;

@end

@implementation CPRegisterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}

- (IBAction)registerBtn:(UIButton *)sender {
    [self loadRegister];
}

-(void)loadRegister {
    if (self.username.text.length <= 0) {
        [ProgressHUD show:@"请输入昵称"];return;
    }
    if (self.username.text.length <= 6) {
        [ProgressHUD show:@"请输入密码"];
        return;
    }
    AVUser * user = [AVUser user];
    user.username = self.username.text;
    user.password = self.password.text;
    // 注册
    [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
        if (succeeded) {
            NSLog(@"注册成功");

            [mNotificationCenter postNotificationName:@"regsiterNotification" object:nil userInfo:@{@"username":self.username.text,@"password":self.password.text}];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                self.tabBarController.selectedIndex = 0;
                [self.navigationController popViewControllerAnimated:YES];
            });
        }else {
            [ProgressHUD show:@"注册失败"];
        }
    }];
}


@end
